
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
  <meta charset="utf-8">
  <title>IOS中Property的修饰字 - 许龙武的技术博客</title>
  <meta name="author" content="许龙武">

  
  <meta name="description" content="assign、copy 、retain（MRC） assign: 对基础数据类型 （NSInteger）和C数据类型（int, float, double, char,等）
copy：对NSString（不用同一块内存）
retain：对其他NSObject和其子类（用同一块内存） &hellip;">
  

  <!-- http://t.co/dKP3o1e -->
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  
  <link rel="canonical" href="http://loongwoo.github.io/blog/2015/07/06/at-ioszhong-propertyde-xiu-shi-zi/">
  <link href="/favicon.png" rel="icon">
  <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
  <link href="/atom.xml" rel="alternate" title="许龙武的技术博客" type="application/atom+xml">
  <script src="/javascripts/modernizr-2.0.js"></script>
  <script src="http://cdn.staticfile.org/jquery/1.9.1/jquery.min.js"></script>
  <script>!window.jQuery && document.write(unescape('%3Cscript src="/javascripts/libs/jquery.min.js"%3E%3C/script%3E'))</script>
  <script src="/javascripts/octopress.js" type="text/javascript"></script>
  

</head>

<body   >
  <header role="banner"><hgroup>
  <h1><a href="/">许龙武的技术博客</a></h1>
  
    <h2>记录所学，快乐分享</h2>
  
</hgroup>

</header>
  <nav role="navigation"><ul class="subscription" data-subscription="rss">
  <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
  
</ul>
  
<form action="https://www.google.com/search" method="get">
  <fieldset role="search">
    <input type="hidden" name="sitesearch" value="loongwoo.github.io">
    <input class="search" type="text" name="q" results="0" placeholder="Search"/>
  </fieldset>
</form>
  
<ul class="main-navigation">
	<li><a href="/">首页</a></li>
	<li><a href="/blog/archives">所有文章</a></li>
	<li><a href="http://weibo.com/loongwoo">我的微博</a></li>
</ul>

</nav>
  <div id="main">
    <div id="content">
      <div>
<article class="hentry" role="article">
  
  <header>
    
      <h1 class="entry-title">IOS中Property的修饰字</h1>
    
    
      <p class="meta">
        




<time class='entry-date' datetime='2015-07-06T09:42:07+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>6</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>9:42 am</span></time>
        
      </p>
    
  </header>


<div class="entry-content"><h2>assign、copy 、retain（MRC）</h2>

<ul>
<li>assign: 对基础数据类型 （NSInteger）和C数据类型（int, float, double, char,等）</li>
<li>copy：对NSString（不用同一块内存）</li>
<li>retain：对其他NSObject和其子类（用同一块内存）

<h2>readonly、readwrite</h2></li>
<li>readonly：只读</li>
<li><p>readwrite：读写（默认属性）</p>

<h2>weak、strong（ARC下避免循环引用需要申明weak指针）</h2>

<p><a href="http://www.2cto.com/kf/201409/332193.html">三种容易引起循环引用的场景</a></p></li>
<li><p>weak：指针指向的地址一旦被释放，这些指针都将被赋值为nil。这样的好处能有效的防止野指针。</p></li>
<li>strong：strong就相当于retain属性，而weak相当于assign<br />
<strong>具体一点：IBOutlet可以为weak，NSString为copy，delegate一般为weak，其他的看情况。一般来说，类“内部”的属性设置为strong，类“外部”的属性设置为weak。说到底就是一个归属权的问题。小心出现循环引用导致内存无法释放。</strong>

<h2>nonatomic、atomic</h2></li>
<li>nonatomic：不加同步，多线程并发访问会提高性能。</li>
<li>atomic：默认值<br />
了解<a href="http://www.parallellabs.com/2011/04/09/pthread-mutex-lock-and-thread-safety/">原子操作</a>，以及<a href="http://blog.csdn.net/cubepeng/article/details/7735962">非原子操作的效率提升</a>。</li>
</ul>


<h2>参考链接</h2>

<p>[<a href="http://www.aichengxu.com/view/32930">http://www.aichengxu.com/view/32930</a>]<br />
[<a href="http://www.2cto.com/kf/201205/133943.html">http://www.2cto.com/kf/201205/133943.html</a>]</p>
</div>


  <footer>
    <p class="meta">
      
  

<span class="byline author vcard">Posted by <span class="fn">许龙武</span></span>

      




<time class='entry-date' datetime='2015-07-06T09:42:07+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>6</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>9:42 am</span></time>
      


      <br>原文链接：<a href="http://loongwoo.github.io/blog/2015/07/06/at-ioszhong-propertyde-xiu-shi-zi/">http://loongwoo.github.io/blog/2015/07/06/at-ioszhong-propertyde-xiu-shi-zi/</a>
 <!-- 添加这一行代码 -->
    </p>
    
      <div class="sharing">
  
  
  
  
  <!-- JiaThis Button BEGIN -->
<div class="jiathis_style_32x32">
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_renren"></a>
  <a href="http://www.jiathis.com/share?uid=2043882" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">var jiathis_config = {data_track_clickback:'true'};</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=2043882" charset="utf-8"></script>
<!-- JiaThis Button END -->

<!--UY BEGIN -->
<div id="uyan_frame"></div>
<script type="text/javascript" src="http://v2.uyan.cc/code/uyan.js?uid=2043882"></script>
<!--UY END -->

  
</div>

    
    <p class="meta">
      
        <a class="basic-alignment left" href="/blog/2015/07/05/at-iosshu-xing-he-cheng-yuan-bian-liang/" title="Previous Post: IOS属性和成员变量">&laquo; IOS属性和成员变量</a>
      
      
        <a class="basic-alignment right" href="/blog/2015/07/07/at-ios-appqi-dong-yin-dao-jie-mian/" title="Next Post: IOS App启动引导界面">IOS App启动引导界面 &raquo;</a>
      
    </p>
  </footer>
</article>

</div>

<aside class="sidebar">
  
    <section>
  <h1>最新文章</h1>
  <ul id="recent_posts">
    
      <li class="post">
        <a href="/blog/2016/01/28/stringmanage-a-xcode-plugin-for-managing-your-strings/">StringManage -- a Xcode Plugin for Managing Your Strings</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/12/iosshi-yong-bundle/">iOS使用Bundle</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/12/iosduo-ge-localizable-dot-strings/">IOS多个Localizable.strings</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/11/iosxian-zhi-uitextfieldchang-du/">IOS限制UITextField长度</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/11/ioszi-dong-bu-ju-constraintswithvisualformat/">IOS自动布局constraintsWithVisualFormat</a>
      </li>
    
  </ul>
</section>




<section>
	<h1>关于我</h1>
    <p>程序员、创业者、IOS开发工程师
	<br/>新浪微博：<a href='http://weibo.com/loongwoo' target='_blank'>商陆_Xu</a>
	<br/>新浪博客：<a href="http://blog.sina.com.cn/lunaize" target="_blank" title="商陆的博客">商陆</a>
	<br/>GitHub：<a href='https://github.com/loongwoo' target='_blank'>Loongwoo</a>
	<br/>Git@OSC: <a href='http://git.oschina.net/redder_xu' target='_blank'>redder_xu</a>
    <br/>CSDN博客：<a href="http://blog.csdn.net/redder_xu" target="_blank" title="CSDN">霜叶红于二月花</a>
	<br/>个人微信：xulongwu77 欢迎调戏
	<br/><img width="220px" src="/images/myweixin.jpg" />
	</p>
</section>
<section>
  <h1>友情链接</h1>
  <ul>
  <li><a href="http://blog.devtang.com" target="_blank" title="唐巧的技术博客">唐巧的技术博客</a></li>
  <li><a href="http://www.leichunfeng.com" target="_blank" title="雷纯锋的技术博客">雷纯锋的技术博客</a></li>
  <li><a href="http://www.superqq.com" target="_blank" title=“刚刚在线”>刚刚在线</a></li>
  </ul>
</section>

  
</aside>


    </div>
  </div>
  <footer role="contentinfo"><p>
  Copyright &copy; 2017 - 许龙武 -
  <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
  <script language="javascript" type="text/javascript" src="http://js.users.51.la/17858326.js"></script>
<noscript><a href="http://www.51.la/?17858326" target="_blank"><img alt="&#x6211;&#x8981;&#x5566;&#x514D;&#x8D39;&#x7EDF;&#x8BA1;" src="http://img.users.51.la/17858326.asp" style="border:none" /></a></noscript>

</p>

</footer>
  











</body>
</html>
